package com.zn.utils
{

    public class ArrayUtil
    {
        public function ArrayUtil()
        {
        }

        /**
         *从列表中查找某一项
         * @param source
         * @param field
         * @param value
         * @return
         *
         */
        public static function findItem(source:Array, field:String, value:*):*
        {
            var element:Object;
            for (var i:int = 0; i < source.length; i++)
            {
                element = source[i] as Object;
                if (element.hasOwnProperty(field) && element[field] == value)
                    return element;
            }

            return null;
        }

        /**
         * 从列表中查找某一项 返回其索引
         * @param source
         * @param field
         * @param value
         * @return
         *
         */
        public static function findItemIndex(source:Array, field:String, value:*):int
        {
            var element:Object;
            for (var i:int = 0; i < source.length; i++)
            {
                element = source[i] as Object;
                if (field != "" && field != null &&
                    element.hasOwnProperty(field) && element[field] == value)
                    return i;
                else if (element == value)
                    return i;
            }

            return -1;
        }
    }
}